/**
 *
 */
package com.fitns.user.utils;

import sun.misc.BASE64Decoder;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * ClassName:Base64Util <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2015年10月21日 下午3:49:21 <br/>
 *
 * @author chiwei
 * @version
 * @since JDK 1.6
 * @see
 */
public class DeEnCode {

    public static String encode(String s) {
        if (s == null)
            return null;
        String res = "";
        try {
            res = new sun.misc.BASE64Encoder().encode(s.getBytes("GBK"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return res;
    }


    /**
     * 将 BASE64 编码的字符串 s 进行解码
     */
    public static String decode(String s) {
        if (s == null)
            return null;
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            byte[] b = decoder.decodeBuffer(s);
            return new String(b,"GBK");
        } catch (Exception e) {
            return null;
        }

    }
    public static void main(String args[]){
        System.out.println(encode("a12345678"));
        System.out.println(decode("YTEyMzQ1Njc4"));
    }



}
